package com.reborn.mall.api.service.impl;

import com.reborn.mall.api.model.vo.WelcomeInfoVO;
import com.reborn.mall.api.service.OrderService;
import com.reborn.mall.api.service.WelcomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * TODO: Here is description
 *
 * @author Reborn
 * @since 2020/4/10
 */
@Service
public class WelcomeServiceImpl implements WelcomeService {

    @Autowired
    private OrderService orderService;

    @Override
    public WelcomeInfoVO data() {
        LocalDateTime now = LocalDateTime.now();

        String today = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        String yesterday = now.minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

        int todayTotalOrderCount = orderService.getTotalOrderCountOfDate(today);
        BigDecimal todayTotalSalesAmount = orderService.getTotalSalesAmountOfDate(today);
        BigDecimal yesterdayTotalSalesAmount = orderService.getTotalSalesAmountOfDate(yesterday);

        WelcomeInfoVO welcomeInfoVO = new WelcomeInfoVO();
        welcomeInfoVO.setTodayTotalOrderCount(todayTotalOrderCount);
        welcomeInfoVO.setTodayTotalSalesAmount(todayTotalSalesAmount);
        welcomeInfoVO.setYesterdayTotalSalesAmount(yesterdayTotalSalesAmount);
        return welcomeInfoVO;
    }
}
